May Listing 2
         TTL "SPEED/ASM Demo"
;
;************************************
;*                                  *
;* Listing Two: SPEED/ASM Demo      *
;*              program             *
;*                                  *
;************************************
;
;
;
FALSE    EQU 0
TRUE     EQU 1
CR       EQU $8D
;
;
;
;
;
; SPEED/ASM ENTRY POINTS
; (Only the equates necessary for
;  this demo are included.)
;
;
;
; NOTE: THE EQUATE OF PUTC MUST
; BE CHANGED IF YOU RELOCATE
; SPEED/ASM TO SOME LOCATION
; OTHER THAN $7800
;
PUTC     EQU $7800
GETC     EQU PUTC+3
SAGL     EQU GETC+3          ;FOR USE BY S/A ONLY- SEE DOC.
SAPC     EQU SAGL+3          ; "   "   "  "   "     "   "
HOME     EQU SAPC+3          ;HOME AND CLEAR
READLN   EQU HOME+3
INIT     EQU READLN+3
FOR      EQU INIT+3
FOR0     EQU FOR+3
NEXT     EQU FOR0+3
IFI      EQU NEXT+3
IFI0     EQU IFI+3
IFS      EQU IFI0+3
IFS0     EQU IFS+3
MOVE     EQU IFS0+3
LOAD     EQU MOVE+3
MOVS     EQU LOAD+3
LDSTR    EQU MOVS+3
PRINT    EQU LDSTR+3
PRTSTR   EQU PRINT+3
PRTINT   EQU PRTSTR+3
RDSTR    EQU PRTINT+3
RDINT    EQU RDSTR+3
ONXGOTO  EQU RDINT+3
CASE     EQU ONXGOTO+3
CASEI    EQU CASE+3
INSET    EQU CASEI+3
NOTINSET EQU INSET+3
ABS      EQU NOTINSET+3
NEG      EQU ABS+3
MUL      EQU NEG+3
DIV      EQU MUL+3
MOD      EQU DIV+3
RND      EQU MOD+3
;
;
;
; Apple monitor equates;
;
EXIT     EQU $FF69           ; Address to quit S/A.
;
;
;
; ****************************
;
;
; NOTE: INIT must be called before
; any other SPEED/ASM routine.
;
START    JSR INIT
;
;
; The following code loads 10 into
; "I" and 54 into "J" the computes
; there sum, difference, product,
; quotient, and remainder.
;
         JSR LOAD
         ADR 10,I
         JSR LOAD
         ADR 54,J
;
; Compute the sum:
;
LOOP     CLC                 ; Always CLC before addition.
         LDA I
         ADC J
         STA SUM
         LDA I+1
         ADC J+1
         STA SUM+1
         BVS OVERFLOW        ; Check for >32767.
;
; Calculate the difference:
;
         SEC                 ; Always SEC before subtraction.
         LDA I
         SBC J
         STA DIFFRNCE
         LDA I+1
         SBC J+1
         STA DIFFRNCE+1
         BVS OVERFLOW
;
; Calculate the product:
;
         JSR MUL
         ADR I,J,PRODUCT
         BVS OVERFLOW
;
; Calculate the quotient
;
         JSR DIV
         ADR J,I,QUOTIENT    ; J/I, not I/J
         BVS OVERFLOW
;
; Calculate the remainder
;
         JSR MOD
         ADR J,I,REMANDR
         BVS OVERFLOW
;
;
; Generate a couple of random numbers
;
         JSR RND
         ADR RANDOM1
         JSR ABS
         ADR RANDOM1
         BVS OVERFLOW
;
         JSR RND
         ADR RANDOM2
         JSR ABS
         ADR RANDOM2
         BVS OVERFLOW
         JSR NEG
         ADR RANDOM2
         BVS OVERFLOW
;
         JSR RND
         ADR RANDOM3
         JSR NEG
         ADR RANDOM3
         BVS OVERFLOW
;
         JSR RND
         ADR RANDOM4
         JMP PRTNUMS
;
OVERFLOW JSR PRINT
         BYT CR,CR,"Overflow occured",CR,0
         JMP EXIT
;
;
;
; Print the sum:
;
PRTNUMS  JSR PRINT
         BYT "I= ",0
         JSR PRTINT
         ADR I
         JSR PRINT
         BYT CR,"J= ",0
         JSR PRTINT
         ADR J
;
         JSR PRINT
         BYT CR,"The sum is ",0
         JSR PRTINT
         ADR SUM
;
; Print the difference:
;
         JSR PRINT
         BYT CR,"The difference (I-J) is ",0
         JSR PRTINT
         ADR DIFFRNCE
;
; Print the product:
;
         JSR PRINT
         BYT CR,"The product is ",0
         JSR PRTINT
         ADR PRODUCT
;
; Print the quotient
;
         JSR PRINT
         BYT CR,"The quotient (J/I) is ",0
         JSR PRTINT
         ADR QUOTIENT
;
; Print the reminder:
;
         JSR PRINT
         BYT CR,"The remainder (J mod I) is ",0
         JSR PRTINT
         ADR REMANDR
;
; Print the random numbers:
;
         JSR PRINT
         BYT CR,"The random numbers are:"
         BYT CR,"Random1: ",0
         JSR PRTINT
         ADR RANDOM1
         JSR PRINT
         BYT CR,"Random2: ",0
         JSR PRTINT
         ADR RANDOM2
         JSR PRINT
         BYT CR,"Random3: ",0
         JSR PRTINT
         ADR RANDOM3
         JSR PRINT
         BYT CR,"Random4: ",0
         JSR PRTINT
         ADR RANDOM4
;
;
; Demonstrate the MOVE subroutine
;
         JSR PRINT
         BYT CR,CR,"Current contents of I is ",0
         JSR PRTINT
         ADR I
         JSR PRINT
         BYT CR,"Current contents of J is ",0
         JSR PRTINT
         ADR J
;
         JSR MOVE
         ADR I,J
;
         JSR PRINT
         BYT CR,"Now I contains ",0
         JSR PRTINT
         ADR I
         JSR PRINT
         BYT CR,"and J contains ",0
         JSR PRTINT
         ADR J
;
;
; Ask the user if he wants to re-run
; the program with user input.
;
;
RERUN    JSR PRINT
         BYT CR,CR,"Do you wish to re-run this",CR
         BYT "program (Y/N)? ",0
         JSR GETC
         AND #$DF            ;Convert Lower case to Upper case
         JSR PUTC
         CMP #"N"
         BNE >1
         JMP EXIT
;
^1       CMP #"Y"
         BNE RERUN
;
;
; If so, get new values for I and J
;
;
BADNUM1  JSR PRINT
         BYT CR
         BYT "Enter a new value for I:",0
         JSR READLN
         JSR RDINT
         ADR I
         BVC GOODNUM1
         JSR PRINT
         BYT CR,"Error in entry, re-enter",CR,0
         JMP BADNUM1
;
GOODNUM1 JSR PRINT
         BYT CR,"Enter a new value for J:",0
         JSR READLN
         JSR RDINT
         ADR J
         BVC >0
         JSR PRINT
         BYT CR,"Bad value for J, re-enter",CR,0
         JMP GOODNUM1
;
^0       JMP LOOP
;
;
;
;
;
;
;
;
;***********************************
;
; Variable declarations:
;
; The following variables are all
; integers. So they are declared
; with the ADR pseudo opcode to
; reserve two bytes for each integer.
;
;
I        ADR 0
J        ADR 0
;
SUM      ADR 0
PRODUCT  ADR 0
QUOTIENT ADR 0
DIFFRNCE ADR 0
REMANDR  ADR 0
RANDOM1  ADR 0
RANDOM2  ADR 0
RANDOM3  ADR 0
RANDOM4  ADR 0
;
         END 
